package com.mldong.modules.cms.controller;

import com.mldong.auth.Perm;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.cms.dto.SlidePageParam;
import com.mldong.modules.cms.dto.SlideParam;
import com.mldong.modules.cms.service.SlideService;
import com.mldong.modules.cms.vo.SlideVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 幻灯片 前端控制器
    * </p>
*
* @author mldong
* @since 2022-10-23
*/
@RestController
@Api(tags = "幻灯片管理")
@RequiredArgsConstructor
public class SlideController {
    private final SlideService slideService;
    /**
     * 添加幻灯片
     * @param param
     * @return
     */
    @PostMapping("/cms/slide/save")
    @ApiOperation(value = "添加幻灯片")
    @Perm
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) SlideParam param) {
        slideService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除幻灯片
     * @param param
     * @return
     */
    @PostMapping("/cms/slide/remove")
    @ApiOperation(value = "删除幻灯片")
    @Perm
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        slideService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改幻灯片
     * @param param
     * @return
     */
    @PostMapping("/cms/slide/update")
    @ApiOperation(value = "修改幻灯片")
    @Perm
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) SlideParam param) {
        slideService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个幻灯片
     * @param param
     * @return
     */
    @PostMapping("/cms/slide/detail")
    @ApiOperation(value = "查询单个幻灯片")
    @Perm
    public CommonResult<SlideVO> detail(@RequestBody IdParam param) {
        SlideVO slide = slideService.findById(param.getId());
        return CommonResult.data(slide);
    }
    /**
     *分页查询幻灯片列表
     * @param param
     * @return
     */
    @PostMapping("/cms/slide/page")
    @ApiOperation(value = "分页查询幻灯片列表")
    @Perm
    public CommonResult<CommonPage<SlideVO>> page(@RequestBody SlidePageParam param) {
        return CommonResult.data(slideService.page(param));
    }
}
